//
//  OrderDetailViewController.m
//  B2C
//
//  Created by 李小龙 on 2017/8/2.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "OrderDetailTableViewCell.h"
#import "RefundViewController.h"
#import "OrderHalfButton.h"
#import "LogisticsViewController.h"
#import "EvaluateViewController.h"
#import "GoodDetailViewController.h"
//#import "LogisticsWebViewController.h"
#import "LogisticsViewController.h"
#import <AlipaySDK/AlipaySDK.h>
#import "PayStatusViewController.h"

@interface OrderDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UILabel *bottomLabel;
@property (weak, nonatomic) IBOutlet UIView *receiptTypeBackView;
@property (weak, nonatomic) IBOutlet UIButton *receiptTypeButton;
@property (weak, nonatomic) IBOutlet UIView *receiptTitleBackView;
@property (weak, nonatomic) IBOutlet UIButton *receiptTitleLabel;
@property (weak, nonatomic) IBOutlet UIView *receiptNameBackView;
@property (weak, nonatomic) IBOutlet UILabel *receiptNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *receiptNameTF;
@property (weak, nonatomic) IBOutlet UIView *receiptNumberBackView;
@property (weak, nonatomic) IBOutlet UITextField *receiptNumberTF;


@end

@implementation OrderDetailViewController
#pragma mark - ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"订单详情";
    [self.tableView clearExtendCellLine];
    [self getNetData];
}
- (void)disMissSelf {
    switch (self.fromType) {
        case FromTypeStatus:
        {
            [self popToRootViewController];
        } break;
        case FromTypeOther:
        {
            [super disMissSelf];
        } break;
        default:
            break;
    }
}
#pragma mark - 网络请求
- (void)getNetData {
    // 根据订单id获取订单详细信息
    [MBProgressHUD showHUDProgress:self.view animated:YES];
    [MYAFNetworking POST:URL_Get_Order_Detail parameters:@{@"omid":self.detailModel.omid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if ([responseObject[@"code"] isEqualToString:@"200"]) {
            self.detailModel = [OrderModel mj_objectWithKeyValues:responseObject[@"data"]];
            [self.tableView reloadData];
//            if ([self.detailModel.omstatus isEqualToString:@"6"]) {
//                [self.bottomView setHidden:YES];
//            } else {
//                [self.bottomView setHidden:NO];
//                [self createBottomView];
//            }
            [self updateTableViewFooterView];
            [self createBottomView];
        } else {
            [MBProgressHUD showError:self.view title:responseObject[@"message"] code:responseObject[@"code"] animated:YES];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showError:self.view title:@"" code:@"" animated:YES];
    }];
}
#pragma mark - action
- (void)updateTableViewFooterView {
    if ([self.detailModel.ominvoicetype isEqualToString:@"0"]) {
        // 不开发票
        [self.receiptTypeButton setTitle:@"不开发票" forState:UIControlStateNormal];
        [self.receiptTitleBackView setHidden:YES];
        [self.receiptNameBackView setHidden:YES];
        [self.receiptNumberBackView setHidden:YES];
    } else {
        // 普通发票
        [self.receiptTypeButton setTitle:@"普通发票" forState:UIControlStateNormal];
        [self.receiptNameTF setText:self.detailModel.ominvoicename];
        if ([self.detailModel.ominvoicerise isEqualToString:@"0"]) {
            // 个人
            [self.receiptTitleLabel setTitle:@"个人" forState:UIControlStateNormal];
            [self.receiptNameLabel setText:@"发票姓名"];
            [self.receiptNumberBackView setHidden:YES];
        } else {
            // 企业
            [self.receiptTitleLabel setTitle:@"企业" forState:UIControlStateNormal];
            [self.receiptNameLabel setText:@"发票名称"];
            [self.receiptNumberBackView setHidden:NO];
            [self.receiptNumberTF setText:self.detailModel.ominvoicenumber];
        }
    }
    
}
- (void)createBottomView {
    // 根据type显示都是什么按钮
    CGFloat buttonY = 11;
    CGFloat buttonW = 75;
    CGFloat kong = 15;
    
    [self.bottomView removeAllSubviews];
    switch (self.detailModel.omstatus.intValue) {
        case 0:
        {
            for (NSInteger i = 1; i <= 2; i++) {
                CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.bottomView.height-buttonY*2);// self.fourthBackView.width
                
                OrderButtonType type;
                NSString *buttonTitle;
                UIColor *color, *borderColor;
                if (i == 1) {
                    type = OrderButtonTypePay;
                    buttonTitle = @"付款";
                    color = [UIColor orangePriceColor];
                    borderColor = [UIColor orangePriceColor];
                } else {
                    type = OrderButtonTypeCancel;
                    buttonTitle = @"取消订单";
                    color = [UIColor blackTextColor];
                    borderColor = [UIColor grayTextColor];
                }
                
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [self.bottomView addSubview:button];
                
            }
        } break;
        case 1:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeAlert frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.bottomView.height-buttonY*2) buttonTitle:@"提醒发货" color:[UIColor orangePriceColor] borderColor:[UIColor orangePriceColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.bottomView addSubview:button];
        } break;
        case 2:
        {
            for (NSInteger i = 1; i <= 2; i++) {
                CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.bottomView.height-buttonY*2);// self.fourthBackView.width
                
                OrderButtonType type;
                NSString *buttonTitle;
                UIColor *color, *borderColor;
                if (i == 1) {
                    type = OrderButtonTypeSure;
                    buttonTitle = @"确认收货";
                    color = [UIColor orangePriceColor];
                    borderColor = [UIColor orangePriceColor];
                } else {
                    type = OrderButtonTypeCheck;
                    buttonTitle = @"查看物流";
                    color = [UIColor blackTextColor];
                    borderColor = [UIColor grayTextColor];
                }
                
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [self.bottomView addSubview:button];
                
            }
        } break;
        case 3:
        {
            for (NSInteger i = 1; i <= 3; i++) {
                CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.bottomView.height-buttonY*2);// self.fourthBackView.width
                
                OrderButtonType type;
                NSString *buttonTitle;
                UIColor *color, *borderColor;
                if (i == 1) {
                    type = OrderButtonTypeEvaluate;
                    buttonTitle = @"评价";
                    color = [UIColor orangePriceColor];
                    borderColor = [UIColor orangePriceColor];
                } else if (i == 2) {
                    type = OrderButtonTypeDelete;
                    buttonTitle = @"删除订单";
                    color = [UIColor blackTextColor];
                    borderColor = [UIColor grayTextColor];
                } else {
                    type = OrderButtonTypeCheck;
                    buttonTitle = @"查看物流";
                    color = [UIColor blackTextColor];
                    borderColor = [UIColor grayTextColor];
                }
                
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [self.bottomView addSubview:button];
                
            }
        } break;
        case 4:
        {
            for (NSInteger i = 1; i <= 2; i++) {
                CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.bottomView.height-buttonY*2);// self.fourthBackView.width
                
                OrderButtonType type;
                NSString *buttonTitle;
                UIColor *color, *borderColor;
                if (i == 1) {
                    type = OrderButtonTypeDelete;
                    buttonTitle = @"删除订单";
                    color = [UIColor orangePriceColor];
                    borderColor = [UIColor orangePriceColor];
                } else {
                    type = OrderButtonTypeCheck;
                    buttonTitle = @"查看物流";
                    color = [UIColor blackTextColor];
                    borderColor = [UIColor grayTextColor];
                }
                
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [self.bottomView addSubview:button];
                
            }
        } break;
        case 5:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeDelete frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.bottomView.height-buttonY*2) buttonTitle:@"删除订单" color:[UIColor orangePriceColor] borderColor:[UIColor orangePriceColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.bottomView addSubview:button];
        } break;
        case 6:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeCheck frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.bottomView.height-buttonY*2) buttonTitle:@"查看物流" color:[UIColor blackTextColor] borderColor:[UIColor grayTextColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.bottomView addSubview:button];
        } break;
        case 7:
        {
            
        } break;
        case 8:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeDelete frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.bottomView.height-buttonY*2) buttonTitle:@"删除订单" color:[UIColor orangePriceColor] borderColor:[UIColor orangePriceColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.bottomView addSubview:button];
        } break;
        default:
            break;
    }
}
- (void)refundAction {
    // 点击“申请退款”按钮时跳转
    RefundViewController *refundVC = [[RefundViewController alloc] init];
    refundVC.detailModel = self.detailModel;
    [self.navigationController pushViewController:refundVC animated:YES];
}
- (void)copyButtonAction {
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = self.detailModel.omid;
    [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"订单编号已拷贝" animated:YES];
}
- (void)orderButtonAction:(OrderHalfButton *)button {
    switch (button.type) {
        case OrderButtonTypePay:
            [self payAction:self.detailModel];
            break;
        case OrderButtonTypeCancel:
//            [self evaluateAction:self.detailModel];
            [self cancelAction:self.detailModel];
            break;
        case OrderButtonTypeAlert:
            [self alertAction:self.detailModel];
            break;
        case OrderButtonTypeCheck:
            [self checkAction:self.detailModel];
            break;
        case OrderButtonTypeSure:
            [self sureAction:self.detailModel];
            break;
        case OrderButtonTypeDelete:
            [self deleteAction:self.detailModel];
            break;
        case OrderButtonTypeEvaluate:
            [self evaluateAction:self.detailModel];
            break;
        default:
            break;
    }
}
// 支付
- (void)uploadWechatPay:(NSDictionary *)parameters {
    if (![WXApi isWXAppInstalled]) {
        [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"没有安装微信" animated:YES];
        return;
    }
    if (![WXApi isWXAppSupportApi]) {
        [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"当前微信版本过低" animated:YES];
        return;
    }
    
    PayReq *request   = [[PayReq alloc] init];
    //request.openID    = responseObject[@"data"][@"appId"];
    request.partnerId = Wechat_partnerId;
    request.prepayId  = parameters[@"prepayid"];
    request.package   = parameters[@"package"];//Sign=WXPay
    request.nonceStr  = parameters[@"noncestr"];
    request.timeStamp = [parameters[@"timestamp"] unsignedIntValue];
    request.sign      = parameters[@"sign"];
    if ([WXApi sendReq:request]) {
        NSLog(@"发送成功");
        
    } else {
        NSLog(@"发送失败");
        [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"订单获取失败" animated:YES];
    }
    
}
- (void)uploadAlipay:(NSString *)orderString {
    __weak typeof(self) weakSelf = self;
    // NOTE: 调用支付结果开始支付
    [[AlipaySDK defaultService] payOrder:orderString fromScheme:AppScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"reslut = %@",resultDic);
        if ([resultDic[@"resultStatus"] isEqualToString:@"9000"]) {
            //成功
            PayStatusViewController *statusVC = [[PayStatusViewController alloc] init];
            statusVC.omid = weakSelf.omid;
            statusVC.type = StatusTypePaySuccess;
            
            [weakSelf.navigationController pushViewController:statusVC animated:YES];
        } else {
            //[MBProgressHUD myShowHUDAddedTo:weakSelf.view labelText:@"付款失败" animated:YES];
            PayStatusViewController *statusVC = [[PayStatusViewController alloc] init];
            statusVC.omid = weakSelf.omid;
            statusVC.type = StatusTypePayFail;
            
            [weakSelf.navigationController pushViewController:statusVC animated:YES];
        }
    }];
    
}

/**
 付款
 */
- (void)payAction:(OrderModel *)model {
    NSLog(@"付款 %@",model.omid);
    switch (model.ompaytype.integerValue) {
        case 0:
        {
            // 微信支付
            self.omid = model.omid;
            [self uploadWechatPay:[MYAFNetworking dictionaryWithJsonString:model.wechat]];
        } break;
        case 1:
        {
            // 支付宝
            self.omid = model.omid;
            [self uploadAlipay:model.wechat];
        } break;
        default:
            break;
    }
}
/**
 取消订单
 */
- (void)cancelAction:(OrderModel *)model {
    __block typeof(self) blockSelf = self;
    [self showAlertWithTitleArray:@[@"取消",@"确认"] title:@"温馨提示" message:@"确认取消此订单？" alertStyle:UIAlertControllerStyleAlert];
    self.alertBlock = ^(NSString *actionTitle) {
        if ([actionTitle isEqualToString:@"确认"]) {
            NSLog(@"取消订单 %@",model.omid);
            [MBProgressHUD showHUDProgress:blockSelf.view animated:YES];
            [MYAFNetworking POST:URL_Cancel_Order parameters:@{@"omid":model.omid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                if ([responseObject[@"code"] isEqualToString:@"200"]) {
                    [MBProgressHUD myShowHUDAddedTo:blockSelf.view labelText:@"已取消该订单" animated:YES];
                    if (blockSelf.block) {
                        blockSelf.block(YES);
                    }
                    switch (blockSelf.fromType) {
                        case FromTypeStatus:
                        {
                            [blockSelf popToRootViewController];
                        } break;
                        case FromTypeOther:
                        {
                            [blockSelf disMissSelf];
                        } break;
                        default:
                            break;
                    }
                } else {
                    [MBProgressHUD showError:blockSelf.view title:responseObject[@"message"] code:responseObject[@"code"] animated:YES];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                [MBProgressHUD showError:blockSelf.view title:@"" code:@"" animated:YES];
            }];
        }
    };
    
}
/**
 提醒发货
 */
- (void)alertAction:(OrderModel *)model {
    NSLog(@"提醒发货 %@",model.omid);
    [MBProgressHUD showHUDProgress:self.view animated:YES];
    [MYAFNetworking POST:URL_Order_Remind_Shipment parameters:@{@"omid":model.omid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if ([responseObject[@"code"] isEqualToString:@"200"]) {
            [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"已提醒卖家发货，请耐心等待" animated:YES];
        } else {
            [MBProgressHUD showError:self.view title:responseObject[@"message"] code:responseObject[@"code"] animated:YES];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showError:self.view title:@"" code:@"" animated:YES];
    }];
}
/**
 查看物流
 */
- (void)checkAction:(OrderModel *)model {
    NSLog(@"查看物流 %@",model.omid);
    //MARK:测试 点击“查看物流”按钮时跳转
    LogisticsViewController *logisticsVC = [[LogisticsViewController alloc] init];
    logisticsVC.orderID = model.omid;
    logisticsVC.com = model.lccode;
    logisticsVC.nu = model.omlogisticsnumber;
    logisticsVC.lccompany = model.lccompany;
    logisticsVC.imgUrl = model.orderson.firstObject.gimg;
    [self.navigationController pushViewController:logisticsVC animated:YES];
    
//    LogisticsWebViewController *logisticsVC = [[LogisticsWebViewController alloc] init];
//    logisticsVC.com = model.lccode;
//    logisticsVC.nu = model.omlogisticsnumber;
//    [self.navigationController pushViewController:logisticsVC animated:YES];
}
/**
 确认收货
 */
- (void)sureAction:(OrderModel *)model {
    [self showAlertWithTitleArray:@[@"确认",@"取消"] title:@"温馨提示" message:@"是否确认收货？" alertStyle:UIAlertControllerStyleAlert];
    __block typeof(self) blockSelf = self;
    self.alertBlock = ^(NSString *actionTitle) {
        if ([actionTitle isEqualToString:@"确认"]) {
            NSLog(@"确认收货 %@",model.omid);
            [MBProgressHUD showHUDProgress:blockSelf.view animated:YES];
            [MYAFNetworking POST:URL_Confirm_Receipt parameters:@{@"omid":model.omid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                if ([responseObject[@"code"] isEqualToString:@"200"]) {
                    [blockSelf getNetData];
                } else {
                    [MBProgressHUD showError:blockSelf.view title:responseObject[@"message"] code:responseObject[@"code"] animated:YES];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                [MBProgressHUD showError:blockSelf.view title:@"" code:@"" animated:YES];
            }];
        }
    };
}
/**
 删除订单
 */
- (void)deleteAction:(OrderModel *)model {
    __block typeof(self) blockSelf = self;
    [self showAlertWithTitleArray:@[@"取消",@"确定"] title:@"温馨提示" message:@"确认删除此订单？" alertStyle:UIAlertControllerStyleAlert];
    self.alertBlock = ^(NSString *actionTitle) {
        if ([actionTitle isEqualToString:@"确定"]) {
            NSLog(@"删除订单 %@",model.omid);
            [MBProgressHUD showHUDProgress:blockSelf.view animated:YES];
            [MYAFNetworking POST:URL_Delete_Order parameters:@{@"omid":model.omid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                if ([responseObject[@"code"] isEqualToString:@"200"]) {
                    [MBProgressHUD myShowHUDAddedTo:blockSelf.view labelText:@"已删除该订单" animated:YES];
                    if (blockSelf.block) {
                        blockSelf.block(YES);
                    }
                    switch (blockSelf.fromType) {
                        case FromTypeStatus:
                        {
                            [blockSelf popToRootViewController];
                        } break;
                        case FromTypeOther:
                        {
                            [blockSelf disMissSelf];
                        } break;
                        default:
                            break;
                    }
                } else {
                    [MBProgressHUD showError:blockSelf.view title:responseObject[@"message"] code:responseObject[@"code"] animated:YES];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
                [MBProgressHUD hideHUDForView:blockSelf.view animated:YES];
                [MBProgressHUD showError:blockSelf.view title:@"" code:@"" animated:YES];
            }];
        }
    };
}
/**
 评价
 */
- (void)evaluateAction:(OrderModel *)model {
    NSLog(@"评价 %@",model.omid);
    // 点击“评价”按钮时跳转
    EvaluateViewController *evaluateVC = [[EvaluateViewController alloc] init];
    for (OrdersonModel *temp in model.orderson) {
        EvaluateModel *model = [[EvaluateModel alloc] init];
        model.orderson_model = temp;
        model.gid = temp.gid;
        model.osid = temp.osid;
        model.escore = @"5";
        model.econtent = @"";
        model.eiimgs = @"";
        model.isanonymous = NO;
        
        [evaluateVC.tableArray addObject:model];
    }
    [self.navigationController pushViewController:evaluateVC animated:YES];
    
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    if ([self.detailModel.omstatus isEqualToString:@"0"] || [self.detailModel.omstatus isEqualToString:@"1"]) {
//        return 2;
//    }
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 2;
        case 1:
            return self.detailModel.orderson.count+2;
        case 2:
            return 1;
        default:
            return 0;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderDetailTableViewCell *cell = [OrderDetailTableViewCell orderDetailCellWith:tableView indexPath:indexPath count:self.detailModel.orderson.count];
    [cell updateCellWith:self.detailModel indexPath:indexPath];
    cell.detailBlock = ^(DetailCellClickType type) {
        switch (type) {
            case DetailCellClickTypeRefund:
            {
                [self refundAction];
            } break;
            case DetailCellClickTypeCopy:
            {
                [self copyButtonAction];
            } break;
            default:
                break;
        }
    };
    return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1 && indexPath.row < self.detailModel.orderson.count) {
        OrdersonModel *model = self.detailModel.orderson[indexPath.row];
        GoodDetailViewController *goodVC = [[GoodDetailViewController alloc] init];
        goodVC.gid = model.gid;
        [self.navigationController pushViewController:goodVC animated:YES];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    return 44.0;
                case 1:
                    return 80.0;
                default:
                    return 0;
            }
            break;
        case 1:
        {
            if (indexPath.row == self.detailModel.orderson.count) {
                switch (self.detailModel.omstatus.integerValue) {
                    case 1: case 2: case 3:
                        return 42.0;
                    default:
                        return 0;
                }
                
            } else if (indexPath.row == self.detailModel.orderson.count+1) {
                return 44.0;
            } else {
                return 100.0;
            }
        }
            break;
        case 2:
            return 59.0;
        default:
            return 0;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
//    if (section == 2) {
//        return 0;
//    }
    return 5;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 5)];
    [view setBackgroundColor:[UIColor clearColor]];
    return view;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
